<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/album/SaveComment.class.php
 *
 * 保存相册评论
 *
 * PHP Version 5
 *
 * @package:   class.album
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

//包含相册的工具表
include_once CLASS_PATH.'album/AlbumUtil.class.php';
include_once CLASS_PATH.'user/UserUtil.class.php';

include_once FUNCTION_PATH.'getCurrentDate.fun.php';
include_once FUNCTION_PATH.'getIp.fun.php';
include_once FUNCTION_PATH.'ConvertString.fun.php';

//定义处理的类

class SaveComment extends BaseAction {

   /**
    * 数据库的连接
    */
   private $db;

   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }

   /**
    * 保存软件评论并返回评论的内容
    * @param:  NULL
    * @return: NULL
    * @access: public
    * @static
    */
   public function run() {

      //取得用户发送过来的参数
      //用户名
      $username = $this->getParameter('username');
      $username = urldecode($username);
      if ( !$username || strlen($username) == 0 ) {
         $username = '无名氏';
      }

      //文章的id
      $id = $this->getParameter('id');

      if ( !$id || strlen($id) == 0 ) {
         return;
      }

      $content = $this->getParameter('content');
      $content = urldecode($content);

      if ( !$content || strlen($content) == 0 ) {
         return;
      }


      $now_time = getNoFormateCurrentDate();

      $ips = getIp();
      $ip = $ips['ip'];
      
      $sql = 'insert into album_comment (image_id, user, submitDate, fromaddr, content ) '.
         ' values ( ?, ?, ?, ?, ? ) ';
      //$this->db->debug = 1;
      $sth = $this->db->prepare($sql);
      $this->db->Execute($sth, array (
         $id,
         $username,
         $now_time,
         $ip,
         $content) );



      if ( !$this->db->errorNo() ) {
         header('Content-Type:text/xml;charset=UTF-8');

         echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
         echo "<message>\n";
         echo "<author>$username</author>\n";
         echo "<from>$ip</from>\n";
         echo "<submittime>$now_time</submittime>\n";
         echo "<content>".htmlspecialchars($content)."</content>\n";
         echo "</message>\n";
      }


   }

}



?>
